$(function () {
    //初始化加载
    window.onload = function () {
        getUserInfo();
        getMenuList();

    }
    //请求用户
    function getUserInfo() {
        $.getJSON("sys/user/info?", function (r) {
            $("#userName").html(r.user.username);
            $("#mobile").html(r.user.mobile);
        });
    }

    //请求菜单
    function getMenuList(){
        $.getJSON("sys/menu/navMobile?", function (r) {
             // 循环输出菜单
            var rowArr = [];
            for(var i= 0; i< r.menuList.length ;i++){
                //每行排列三个
                if ((i+1)%3 == 0){ //换行
                    rowArr.push(i+1);
                }
            }
            if (rowArr.length *3 <r.menuList.length ){
                rowArr.push(r.menuList.length);
            }
            var menuHtml = '';
            for (var i=0;i< rowArr.length;i++){
                //生成行
                var row = '<div class="row" style="padding-bottom: 15px">';
                var j = i*3;
                for (j ;j< rowArr[i]; j++ ){
                    var htmlCel = [
                        ' <div class="col-33">',
                        '        <a  href="'+r.menuList[j].url+'" external class="button button-big ">'+r.menuList[j].name+'</a>',
                        '  </div>'
                    ].join("");
                    row += htmlCel;
                }
                row += '</div>';
                menuHtml += row;
            }
            console.log(menuHtml);
            $("#menu").html(menuHtml) ;
            // 输出菜单



        });
    }

    //监听注销事件
   /* $(document).on('click', '.logout', function () {

    })*/

    $.init();
});
